load("@io_bazel_rules_go//go:def.bzl", "go_test")
load("@rules_cc//cc:cc_library.bzl", "cc_library")
load("@rules_cc//cc:cc_test.bzl", "cc_test")

cc_library(
    name = "lib",
    srcs = [
        "lib.cpp",
        "side_effect.cpp",
    ],
    hdrs = [
        "lib.h",
    ],
    alwayslink = True,
)

# used to check that we don't get a "multiple definition" linker errors, and that the side effect
# is performed exactly once, even if imported several times through different targets
cc_library(
    name = "lib_wrapper",
    deps = [":lib"],
)

cc_test(
    name = "test_side_effect_cc",
    srcs = ["test_side_effect.cpp"],
    deps = [
        ":lib",
        ":lib_wrapper",
    ],
)

go_test(
    name = "test_side_effect_go",
    srcs = ["test_side_effect.go"],
    cdeps = [
        ":lib",
        ":lib_wrapper",
    ],
    cgo = True,
)
